package com.qiuling.iot.service.impl;

import com.github.pagehelper.PageHelper;
import com.qiuling.iot.Exception.BusinessException;
import com.qiuling.iot.Exception.code.BaseResponseCode;
import com.qiuling.iot.entity.SysLog;
import com.qiuling.iot.mapper.SysLogMapper;
import com.qiuling.iot.service.LogService;
import com.qiuling.iot.utils.PageUtil;
import com.qiuling.iot.vo.req.SysLogPageReqVO;
import com.qiuling.iot.vo.resp.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author：zhangqiang
 * @Description：
 * @Date：Created in 20:07 2020/2/11
 * @Modified By：
 */
@Service
@Transactional(readOnly = true)
public class LogServiceImpl implements LogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    @Override
    public PageVO<SysLog> pageInfo(SysLogPageReqVO vo) {
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        return PageUtil.getPageVO(sysLogMapper.selectAll(vo));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deletedLog(List<String> logIds) {
        int i = sysLogMapper.batchDeletedLog(logIds);
        if (i == 0) {
            throw new BusinessException(BaseResponseCode.OPERATION_ERROR);
        }
    }
}
